package com.lht.leetcodeDemo;

import org.junit.Test;

import java.util.Arrays;
import java.util.stream.Stream;

/**
 * @author Eric
 * @version 1.0
 * @date 2019-05-27
 */
public class RotateArray {


    @Test
    public void test(){
        int[] arr=new int[]{1,2,3};
        new RotateArray().rotate(arr,2);

        System.out.println(Arrays.toString(arr));
    }
    public void rotate(int[] nums, int k) {
        if(nums.length==1){
            return;
        }
        if(k>nums.length){
            k%=nums.length;
        }
        rotate(nums,0,nums.length-k);
        rotate(nums,nums.length-k,nums.length);
        rotate(nums,0,nums.length);
    }

    /**
     * @author Eric
     * @date 2019/5/27
     * @param nums 数组
     * @param start  开始i位置
     * @param end   结束位置 包头不包位
     * @return void
     * @throws
     **/
    public void  rotate(int[] nums ,int start,int end){
        int tmp;
        for(int i=start,j=0;i<(start+end)/2;i++,j++){
            tmp=nums[i];
            nums[i]=nums[end-1-j];
            nums[end-1-j]=tmp;
        }
    }


}
